/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.common.log;

import com.aduib.boot.common.log.logger.LoggerFactory;
import com.aduib.boot.common.util.StrUtils;
import com.aduib.boot.common.util.caller.CallerUtil;

import java.util.Objects;

/**
 * @description LOG
 * @author zzh
 * @date 2021/9/13 10:13
 */
public class LOG {
  /**
   * trace级别日志
   *
   * @param log
   */
  public static void t(String log) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).trace(log);
    } else {
      LoggerFactory.getLogger(LOG.class).trace(log);
    }
  }

  public static void t(String log, Object... arg) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).trace(StrUtils.format(log,arg));
    } else {
      LoggerFactory.getLogger(LOG.class).trace(StrUtils.format(log,arg));
    }
  }

  /**
   * debug级别日志
   *
   * @param log
   */
  public static void d(String log) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).debug(log);
    } else {
      LoggerFactory.getLogger(LOG.class).debug(log);
    }
  }

  public static void d(String log, Object... arg) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).debug(StrUtils.format(log,arg));
    } else {
      LoggerFactory.getLogger(LOG.class).debug(StrUtils.format(log,arg));
    }
  }

  /**
   * error级别日志
   *
   * @param log
   */
  public static void e(String log) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).error(log);
    } else {
      LoggerFactory.getLogger(LOG.class).error(log);
    }
  }

  /**
   * error级别日志
   *
   * @param throwable
   * @param log
   */
  public static void e(String log, Throwable throwable) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).error(log, throwable);
    } else {
      LoggerFactory.getLogger(LOG.class).error(log, throwable);
    }
  }

  public static void e(String log, Object... arg) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).error(StrUtils.format(log,arg));
    } else {
      LoggerFactory.getLogger(LOG.class).error(StrUtils.format(log,arg));
    }
  }

  /**
   * info级别日志
   *
   * @param log
   */
  public static void i(String log) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).info(log);
    } else {
      LoggerFactory.getLogger(LOG.class).info(log);
    }
  }

  public static void i(String log, Object... arg) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).info(StrUtils.format(log,arg));
    } else {
      LoggerFactory.getLogger(LOG.class).info(StrUtils.format(log,arg));
    }
  }

  public static void w(String log) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).warn(log);
    } else {
      LoggerFactory.getLogger(LOG.class).warn(log);
    }
  }

  public static void w(String log, Object... arg) {
    Class<?> aClass = CallerUtil.getCallerCaller();
    if (Objects.nonNull(aClass)) {
      LoggerFactory.getLogger(aClass).warn(StrUtils.format(log,arg));
    } else {
      LoggerFactory.getLogger(LOG.class).warn(StrUtils.format(log,arg));
    }
  }
}
